package Listener;

import jakarta.servlet.ServletContext;
import jakarta.servlet.annotation.WebListener;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;

@WebListener

public class OnLineListener implements HttpSessionListener {

    private int onlineCount = 500;

    public OnLineListener(){
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        ServletContext context = se.getSession().getServletContext();
        context.setAttribute("onlineCount",onlineCount);
        onlineCount++;
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
       onlineCount--;
       ServletContext context = se.getSession().getServletContext();
       context.setAttribute("onlineCount",onlineCount);
    }
}
